class SearchController < ApplicationController
  def index
    @keyword = params[:keyword] || ''
    #@items = Item.valid.paginate :page => params[:page]
    if @keyword.blank?
      @items = Item.active.paginate :page => params[:page]
    else
      # thingking sphinx

		  @order = params[:order] = params[:order].blank? ? 'global_rating' : params[:order]
		  sort_mode = params[:sort_mode].blank? ? :desc : params[:sort_mode].to_sym
		  conditions = params[:cat1_id].blank? ? {} : { :cat1_id => params[:cat1_id] }
		  
		  @items = Item.active.paginate :page => params[:page], :per_page => 16, :conditions => conditions, :order => @order
      #@items = Item.active.search @keyword, :conditions => conditions, :page => params[:page], :per_page => 16, :order => @order, :sort_mode => sort_mode
    end
  end
end
